﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using DAL;

/// <summary>
///CMSUser 的摘要说明
/// </summary>
public class CMSUser : Frame.BaseModel.FUser
{
    private CMSUser()
    {
    }

    string[] Rights;
    public static bool Login(string LoginName, string Pwd, string UserName)
    {
        using (DataClassesDataContext dc = new DataClassesDataContext())
        {
            css_yhxx u = dc.css_yhxx
                .FirstOrDefault(o => o.yhbh == LoginName && o.yhmm == Pwd || o.yhmc == UserName && o.yhmm == Pwd);
            if (u == null)
            {
                return false;
            }
            else
            {
                Current = new CMSUser()
                {
                    ID = u.yhbh,
                    IsAdmin = (u.IsAdmin == "1"),
                    m_isLogin = true,
                    Name = u.yhmc,
                    UserTypeName = u.sscq,
                    Rights = u.qx.Split('|')
                };
                return true;
            }
        }
    }

    public override bool CheckActionAllow(string ActionID)
    {
        if (!this.IsLogin)//当前是否登录用户
        {
            return false;
        }
        else
        {
            if (IsAdmin)//管理员账号，权限全开
            {
                return true;
            }
            else//其他人员的权限待补充
            {
                return Rights.Contains(ActionID);
            }
        }
    }
}